/*
 * @Author: xuxu12138 1718324422@qq.com
 * @Date: 2024-06-15 11:04:33
 * @LastEditors: xuxu12138 1718324422@qq.com
 * @LastEditTime: 2024-07-01 11:07:03
 * @FilePath: /things-admin/src/view/apk/ApkBloc.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Page } from '@/base/Page';
import { ApkModel } from '@/base/model/apkModel';
import { getApkList, deleteApkItem, addApkVersion , putApkVersion} from '@/base/api/apkApi';
class Form {
    upgradeType = ''
}
export class ApkBloc {
    model: any = {
        downloadUrl: '',
        upgradeType: '',
        versionCode: '',
        versionName: '',
        modifyContent: '',
        apkSize: 0,
        extName: '',
        apkMd5: '',
        updateStatus: 1,
        detailedContent: ''
    };
    form = new Form();
    paged: Page<ApkModel> = new Page<ApkModel>([], 0, 1, 15, 0, []);
    loading = false;
    load(pageIndex: number, pageSize: number) {
        this.loading = true;
        return getApkList({
            pageIndex,
            pageSize,
            upgradeType: this.form.upgradeType,

        }).then((res) => {
            this.paged = res.data;
        }).finally(() => {
            this.loading = false;
        });
    }
    removeItem(row: ApkModel) {
        this.loading = true;
        return deleteApkItem(row.id)
            .finally(() => {
                this.loading = false;
            });
    }
    reset() {
        this.form = new Form();
        this.paged.pageIndex = 1;
        this.paged.pageSize = 15;
        this.load(this.paged.pageIndex, this.paged.pageSize);
    }
    addApkVersion(
        downloadUrl: string,
        apkSize: number,
        modifyContent: string,
        upgradeType: string,
        versionCode: number,
        versionName: string,
        apkMd5: string,
        updateStatus: number,
        detailedContent: string
        ) {
        return addApkVersion({ downloadUrl, apkSize, modifyContent, upgradeType, versionCode, versionName, apkMd5, updateStatus,detailedContent })
    }
    putApkVersion(
        id:number,
        downloadUrl: string,
        apkSize: number,
        modifyContent: string,
        upgradeType: string,
        versionCode: number,
        versionName: string,
        apkMd5: string,
        updateStatus: number,
        detailedContent: string
        ) {
        return putApkVersion({ downloadUrl,id, apkSize, modifyContent, upgradeType, versionCode, versionName, apkMd5, updateStatus,detailedContent })
    }
}
